package com.ibiaoke.goods.service;

import com.ibiaoke.common.base.Page;
import com.ibiaoke.common.utils.AssertUtils;
import com.ibiaoke.goods.dao.AdjustDao;
import com.ibiaoke.goods.entity.Adjust;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class AdjustServiceImpl implements  AdjustService{

    @Autowired
    private AdjustDao adjustDao;

    @Autowired
    private XcxShopPriceService xcxShopPriceService;

    @Transactional
    @Override
    public Integer addAdjust(String userName, Integer shopId,Adjust adjust) {
        AssertUtils.notNull(adjust.getGoodId(), "商品id不能为空");
        AssertUtils.notNull(adjust.getOutShopId(), "调货方id不能为空");
        AssertUtils.notNull(adjust.getInShopId(), "收货方id不能为空");
        AssertUtils.notNull(adjust.getShopId(), "ShopId不能为空");
        AssertUtils.notNull(adjust.getAdjustNum(), "调货数量不能为空");
        adjust.setOperator(userName);
        adjust.setShopId(shopId);
        adjust.setCreateTime(new Date());
        adjustDao.insert(adjust);
        xcxShopPriceService.modifyOutShopNum(adjust);
        return null;
    }

    @Override
    public List<Adjust> findAdjustList(String goodName, Integer goodStockId,Integer goodId, Date adjustTime, Date adjustEndTime , String outName,
                                       String inName, Integer shopId,Page page) {
        return adjustDao.findAdjustList(goodName,goodStockId,goodId,adjustTime,adjustEndTime,outName,inName,shopId,page);
    }

}
